package com.itheima.array;

import java.util.Scanner;

public class ArraySum {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int sum = 0;
        int[] arr = new int[5];
        //将键盘录入的数据存储到数组中
        for (int i = 0; i < arr.length; i++) {
            while (true) {
                System.out.println("请输入第" + (i + 1) + "个整数");
                arr[i] = sc.nextInt();
                if (arr[i] >= 50 && arr[i] <= 100) {
                    break;
                } else {
                    System.out.println("你输入的数据有误");
                    //我的方法太坑了 在for循环中用  i-- 来回退
                    //回退与死循环不一样

                }
            }
        }
        //遍历数组求和
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        System.out.println("sum:" + sum);
    }

}
